import { defineStore } from "pinia";
import { login } from "../service/index";
import { localCache } from "@/ults/cache.js";
import router from "@/router/index"
export const loginStore = defineStore("login", {
  state: () => ({
    from: {
      username: "",
      password: "",
    },
  }),
  actions: {
    getlogin(data) {
      login(data).then((res) => {
        // 登录成功，存储用户信息
        console.log(res);
        localCache.setCache("token", res.data.token);
        localCache.setCache("userinfo", res.data);
        localCache.setCache("menus", res.data.menus);
        router.push("/main");
      });
    },
  },
});
